<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>

  <body>
    <div id="app">
      <cpn></cpn>
    </div>

    <template id="cpn">
      <div>
        我是父组件
        <ccpn></ccpn>
      </div>
    </template>

    <template id="ccpn">
      <div>
        <div>我是子组件</div>
        <button @click="btnChick">按钮</button>
      </div>
    </template>

    <script src="../js/vue.js"></script>
    <script>
      /* 
			1. 访问父组件对象$parent，只能得到上一级组件对象
			2. 访问根组件对象$root
		 */

      const app = new Vue({
        el: '#app',
        data: {
          message: '你好'
        },
        components: {
          cpn: {
            template: '#cpn',
            data() {
              return {
                name: '浮幻'
              }
            },
            components: {
              ccpn: {
                template: '#ccpn',
                methods: {
                  btnChick() {
                    // 1.访问根组件$parent，得到#cpn组件
                    console.log(this.$parent)
                    console.log(this.$parent.name)

                    // 1.访问根组件$root，得到Vue实例组件
                    console.log(this.$root)
                    console.log(this.$root.message)
                  }
                }
              }
            }
          }
        }
      })
    </script>
  </body>
</html>
